package com.sqsf.tset;

import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class MyTest {
    @Test
    public void u1(){
        ClassPathXmlApplicationContext applicationContext=new ClassPathXmlApplicationContext("spring.xml");
        Object u1 = applicationContext.getBean("u1");
        System.out.println(u1);
        applicationContext.close();
    }
    @Test
    public void springC3p0() throws Exception {
        ClassPathXmlApplicationContext applicationContext=new ClassPathXmlApplicationContext("spring.xml");
        ComboPooledDataSource c3p0= (ComboPooledDataSource) applicationContext.getBean("c3p0");
        Connection connection = c3p0.getConnection();
        System.out.println(connection);
        connection.close();
        applicationContext.close();
    }
    @Test
    public void druid() throws Exception {
        //使用无参构造方法创建druid连接池对象
        DruidDataSource druid=new DruidDataSource();
        //通过set方法进行赋值
        druid.setDriverClassName("com.mysql.jdbc.Driver");
        druid.setUrl("jdbc:mysql://localhost:3306/test");
        druid.setUsername("root");
        druid.setPassword("123456");
        //获取连接对象
        Connection connection = druid.getConnection();
        System.out.println(connection);
        //归还连接 关闭连接池
        connection.close();
        druid.close();
    }
}
